package config

import (
	"os"
	"zpay/pkg/config"
	"zpay/pkg/logger"

	"go.uber.org/zap"
)

func init() {
	config.Add("alipay", func() map[string]interface{} {
		private_file := config.Env("ALIPAY_PRIVATE_KEY_FILE", ".secret/alipay_private_key.pem").(string)
		private_key, err := os.ReadFile(private_file)
		if err != nil {
			logger.Fatal("Alipay Config Error:", zap.Error(err))
		}
		public_file := config.Env("ALIPAY_PUBLIC_KEY_FILE", ".secret/alipay_public_key.pem").(string)
		public_key, err := os.ReadFile(public_file)
		if err != nil {
			logger.Fatal("Alipay Config Error:", zap.Error(err))
		}
		return map[string]interface{}{
			// App ID
			"appid":       config.Env("ALIPAY_APPID", ""),
			"private_key": string(private_key),
			"public_key":  string(public_key),
			"notify_url":  config.Env("ALIPAY_NOTIFY_URL", ""),
		}
	})
}
